using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// Summary description for MyPage
/// </summary>
public class MyPage : System.Web.UI.Page
{
    public MyPage()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    #region Fields

    public string username;
    public string role;
    public float discount;
    private bool _isAdminPage;
    private bool _isManagerPage;
    private bool _isDealerPage;
    private bool _isMemberPage;

    #endregion

    //Properties to enable role for each page
    #region Properties

    public bool IsAdminPage
    {
        get { return _isAdminPage; }
        set 
        {
            _isAdminPage = value;
            if (_isAdminPage == true)
            {
                if (!role.Trim().Equals("admin"))
                    Response.Redirect("loginerror.aspx");
            }
        }
    }
    public bool IsManagerPage
    {
        get { return _isManagerPage; }
        set 
        { 
            _isManagerPage = value;
            if (_isManagerPage == true)
            {
                if (!role.Trim().Equals("manager"))
                    Response.Redirect("loginerror.aspx");
            }
        }
    }

    public bool IsDealerPage
    {
        get { return _isDealerPage; }
        set 
        {
            _isDealerPage = value;
            if (_isDealerPage == true)
            {
                if (role.Trim().Equals("customer") || role.Trim().Equals("dealer"))
                {

                }
                else
                {
                    Response.Redirect("loginerror.aspx");
                }
            }
        }
    }

    public bool IsMemberPage
    {
        get { return _isMemberPage; }
        set 
        { 
            _isMemberPage = value;
            if (_isMemberPage == true)
            {
                if (role.Trim().Equals("customer") || role.Trim().Equals("dealer"))
                { 
                
                }
                else
                    Response.Redirect("loginerror.aspx");
            }
        }
    }

    #endregion

    //Check what role is when the page on initialize
    protected override void OnInit(EventArgs e)
    {        
        ///The session Login contains two variables 
        ///- 1: Username 
        ///- 2: Role associated
        ArrayList arr = (ArrayList)HttpContext.Current.Session["Login"];
        if (arr != null)
        {
            //get role and username from session
            username = arr[0].ToString();
            role = arr[1].ToString();
            if(arr[2] != null)
                discount = float.Parse(arr[2].ToString());
        }
        else
        { 
            username = "";
            role = "";
        }
    }
}
